<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
    <meta charset="UTF-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" />
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTable">
    医院编号：
    <div class="layui-inline">
        <input class="layui-input" name="hidnum" id="hidnum" autocomplete="off">
    </div>
    医院名称：
    <div class="layui-inline">
        <input class="layui-input" name="hname" id="hname" autocomplete="off">
    </div>
    <button class="layui-btn" id="searchBtn" data-type="reload">搜索</button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<!-- 自定义的控件 -->
<div id="toolbar" style="display: none; ">
    <div class="layui-btn-group">
<!--        <button class="layui-btn layui-btn-sm" lay-event="add" data-method="notice" data-type="auto"><img src="/static/img/upload.png" style="height: 20px;width: 20px;">&nbsp;添加医院</button>-->
    </div>
</div>
<script type="text/html" id="barDemo">
    <!--    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
<!--    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">恢复</a>
</script>

<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use(['table','layer','jquery'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var $=layui.jquery;

        table.render({
            elem: '#test'
            ,url: '/queryDelCheck'
            // ,height: document.body.clientHeight-180
            ,page: true //开启分页
            , id: 'testReload'
            , cols: [[
                {field: "cid", title: "ID"},
                {field: "cidnum", title: "临床诊断编号"},
                {field: "cname", title: "临床诊断内容"},
                { title: '操作',width:250, toolbar: '#barDemo', align: 'center'}
            ]]
            ,toolbar:'#toolbar'//表格头信息
            ,parseData: function (rs) {//数据格式解析
                console.log(rs);
                if (rs.code == 200) {
                    return {
                        "code": rs.code,
                        "msg": rs.msg,
                        "count": rs.data.totalCount,
                        "data": rs.data

                        //特定的数据交互格式 code  msg count data
                        //拼接    templet:function(){return loname + loname1 +loname2 }
                    }
                }
            },
            response: {	// 设置响应码
                statusCode: 200 //规定成功的状态码，默认：0
            }
        });
        //监听事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.loid);
            switch (obj.event) {
                case 'add':
                    // open("添加用户页面","/view/user/add.html");
                    layer.open({
                        type: 2
                        ,title: "添加页面"
                        ,content:"/static/view/dictionary/addhosp.html?"
                        ,offset: '50px'
                        ,area: ['500px', '60%']
                        ,end:function () {
                            table.reload('testReload');
                        }
                    });
                    break;
            };
        });
        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                open("详情页面","/view/logistics/detail.html?hid="+data.hid);
            } else if (obj.event === 'del') {
                layer.confirm('确认恢复该用户吗？', function(index){
                    $.ajax({
                        type: "POST",
                        url: "/returnCheck",
                        data: {cid: data.cid},
                        dataType:"json",
                        success: function (da) {
                            if (da.code == 200) {
                                layer.msg(da.msg)
                                obj.del(); //删除对应行（tr）的DOM结构
                                // location.reload();//刷新当前页面
                            } else {
                                layer.msg(da.msg)
                            }
                        },
                        error: function (da) {
                            alert("出现错误");
                            return false;
                        }
                    }) //ajax结束
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                // open("用户修改页面","/view/user/edit.html?id="+data.id);
                layer.open({
                    type: 2
                    ,title: "修改页面"
                    ,content:"/static/view/dictionary/edithosp.html?hid="+data.hid
                    ,offset: '50px'
                    ,area: ['500px', '60%']
                    ,end:function () {
                        // console.log("我的父页面的弹框关闭回调方法");
                        table.reload('testReload');
                    }
                });
            }
        });
        //"用户添加页面",
        function open(title,url){
            layer.open({
                type: 2
                ,title: title
                ,content:url
                ,offset: '50px'
                ,area: ['500px', '60%']
                ,end:function () {
                    table.reload('testReload');
                }
            });
        }

        function searchBtn(){

        }

        var $ = layui.$, active = {
            reload: function () {
                var loname = $('#loname');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        "loname": loname.val()
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>

</body>
</html>